$(function () {
    var metas = document.getElementsByTagName("meta");
    if (!metas || metas.length == 0) {
        throw new Error("请添加<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no\">")
    } else {
        var viewport = null;
        for (var start = 0; start < metas.length; start++) {
            if ("viewport" == metas[start].getAttribute("name")) {
                viewport = metas[start];
                break;
            }
        }
        if (viewport)
            viewport.setAttribute('content', 'user-scalable=no, width=device-width, minimum-scale=1, initial-scale=1, maximum-scale=1');
        else
            throw new Error("请添加<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no\">")
    }

    console.log("开发注意：%c 请直接将设计图的px除以40得到当前的rem,在html标签中,添加base属性,指明设计图的设计宽度！！！！！", "color:red ")

    var html = document.getElementsByTagName("html");

    function resize(base) {
        var bi = window.innerWidth / base
        html[0].setAttribute('style', 'font-size: ' + ((bi * 40) < 12 ? 12 : (bi * 40)) + '' + 'px !important');
        var body = document.getElementsByTagName("body");
        body[0].setAttribute('style', 'font-size: 16px !important');
    }

    if (!html[0].getAttribute("base")) {
        throw Error("html未设置base属性，base属性用于标识当前页面的设计宽度");
    }

    resize(parseFloat(html[0].getAttribute("base")))

    window.onresize = function () {
        resize(parseFloat(html[0].getAttribute("base")))
    }
})